package com.yuezhu.util;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;


import com.yuezhu.global.ApplicationContext;

import java.util.ArrayList;
import java.util.List;

/**
 * UI相关工具类 此类包含所有与ui相关的公共方法，包括activity退出等操作
 *      
 * @since 1.0
 * @version 1.0
 * @author liaoww
 * 
 */
public class ActUtils {
	private static List<Activity> mALiveActivity = null;

	/**
	 * 将activity加入集合 每一个activity启动时都需要加入集合进行统一管理
	 * 
	 * @since 1.0
	 * @param activity
	 * @author liaoww
	 */
	public static void createActivity(Activity activity) {
		if (mALiveActivity == null) {
			mALiveActivity = new ArrayList<Activity>(5);
		}
		if (!mALiveActivity.contains(activity)) {
			mALiveActivity.add(activity);
		}
	}

	/**
	 * 销毁指定的activity
	 * 
	 * @param activity
	 * @sine 1.0
	 * @author liaoww
	 */
	public static boolean destroyActivity(Activity activity) {
		if (mALiveActivity == null) {
			return false;
		}
		return mALiveActivity.remove(activity);
	}

	/**
	 * 退出所有activity
	 * 
	 * @since 1.0
	 * @author liaoww
	 */
	public static void finishAllALiveAcitity() {
		if (mALiveActivity == null || mALiveActivity.size() < 1) {
			return;
		}
		for (Activity activity : mALiveActivity) {
			activity.finish();
		}
		mALiveActivity = null;
	}

	/**
	 * 
	 * 退出App
	 * 
	 * @since 1.0
	 * @author user
	 */
	public static void exitApp(Context context) {
		finishAllALiveAcitity();
	}

	public static LayoutInflater getLayoutInflater() {
		return LayoutInflater.from(ApplicationContext.getInstance());
	}

}
